package com.boomkeeper.excel.utils;

import java.io.File;

import org.apache.commons.lang3.StringUtils;
import org.apache.poi.ss.usermodel.Sheet;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.google.common.io.Files;

public class ExcelUtils {
	
	private static final Logger LOGGER = LoggerFactory.getLogger(ExcelUtils.class);

	public static boolean isNew(File file) {
		return isNew(file.getName());
	}
	
	public static boolean isNew(String fullFileName) {
		return "xlsx".equalsIgnoreCase(Files.getFileExtension(fullFileName));
	}
	
	public static boolean isBug(Sheet sheet) {
		String bugValue = sheet.getRow(3).getCell(3).getStringCellValue();
		String reqValue = sheet.getRow(4).getCell(3).getStringCellValue();
		
		if (StringUtils.isBlank(bugValue) && StringUtils.isBlank(reqValue)) {
			LOGGER.error("严重错误，变更单没有填写redmine编号");
			System.exit(0);
		}
		
		return StringUtils.isNotBlank(bugValue);
	}
	
	public static String getRedmine(Sheet sheet) {
		if (isBug(sheet)) {
			return sheet.getRow(3).getCell(3).getStringCellValue();
		} else {
			return sheet.getRow(4).getCell(3).getStringCellValue();
		}
	}
}
